package com.erlang4j.api;

import com.ericsson.otp.erlang.OtpErlangObject;

/**
 * <p>
 * This represents an Erlang mailbox. It has a pid. It can be asked to get data (receive). It can send data from this
 * this. One of the most common patterns of communications is the rpc, so basic support for that is provided
 * </p>
 * <p>
 * Design Notes
 * <ul>
 * <li>The send methods all have a Object parameter serverNameOrPid. Clearly this could be implements as two methods,
 * one with a serverName and one with a pid. I felt that the proliferation of methods was worse than the lack of compile
 * time type safety
 * <li>The {@link IErlang4j} spawn method is probably a better mechanism to receive data from erlang than receive, or
 * rpc
 * <li>The rpc is not very safe: is there is a message in the inbox already it will be processed...
 * </ul>
 * </p>
 * 
 * @author Phil Rice
 */
public interface IMailBox extends ISendMailBox {
	
	/**
	 * read an OptErlangObject that has been sent to you. This is a blocking call. It is almost certainly better to use
	 * a message processor than this method
	 */
	OtpErlangObject receive();

	/**
	 * Composes a message of form {self(),{name,object}} and sends the message. Waits for the reply of form
	 * {ServerId,Data} and returns data. This is a blocking call. It is almost certainly better to use a message
	 * processor than this method
	 */
	OtpErlangObject rpc(String serverNameOrPid, String name, Object object);



}
